package 第二章实用类;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class work2 {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.print("请输入年份");
        int year=input.nextInt();
        System.out.print("请输入月份");
        int month=input.nextInt();
        Calendar calendar=Calendar.getInstance();
        calendar.set(year,month-1,1);
        Date date = calendar.getTime();
        System.out.println("日"+"\t"+"一"+"\t"+"二"+"\t"+"三"+"\t"+"四"+"\t"
                +"五"+"\t"+"六"+"\t");
        int maxDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        for (int i = 1; i <=maxDays ; i++) {
            calendar.set(Calendar.DATE,i);
            int week=calendar.get(Calendar.DAY_OF_WEEK)-1;
           if (calendar.get(Calendar.DATE)==1)

             {
                 for (int j = 0; j <week%7 ; j++) {
                System.out.print(" "+"\t");
             }
               System.out.print(i+"\t");
                 if (week==6){
                     System.out.println();
                 }
             }
          if (calendar.get(Calendar.DATE)!=1) {
              if (week!=6){
                  System.out.print(i+"\t");}
              if (week==6){
                  System.out.println(i+"\t");
                  System.out.println();
           }
          }
        }
    }
}
